<?php
/* 	These code was generated using phpCIGen v 2.a (21/05/2012)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com, 
	#CV. Trust Solution, jl. Saronojiwo 2/19 Surabaya, http://www.ts.co.id
	
	+ Module  		: t_negosiasi Controller
	+ Description	: For record controller process back-end
	+ Filename 		: C_t_negosiasi.php
 	+ creator 		: 
 	+ Created on 24/Jul/2012 10:52:52
	
*/

//class of t_negosiasi
class C_t_negosiasi extends CI_Controller {

	//constructor
	function __construct(){
		parent::__construct();
		$this->load->model('m_t_negosiasi', '', TRUE);
		// $this->load->helper('dompdf');
		$this->load->helper('file');
		
		checkLogin();
	}
	
	function negosiasidet_list(){
		$start = (integer) (isset($_POST['start']) ? @$_POST['start'] : @$_GET['start']);
		$end = (integer) (isset($_POST['limit']) ? @$_POST['limit'] : @$_GET['limit']);
		$negosiasi_id = (integer) (isset($_POST['negosiasi_id']) ? @$_POST['negosiasi_id'] : @$_GET['negosiasi_id']);
		$branch = (integer) (isset($_POST['branch_id']) ? @$_POST['branch_id'] : @$_GET['branch_id']);
		$project = (integer) (isset($_POST['project_id']) ? @$_POST['project_id'] : @$_GET['project_id']);
		$task = isset($_POST['task']) ? @$_POST['task'] : @$_GET['task'];
		$result=$this->m_t_negosiasi->negosiasidet_list($task,$negosiasi_id,$branch,$project,$start,$end);
		echo $result;
	}
	
	function get_nosurat_byvendor(){
		$nosurat = isset($_POST['nosurat']) ? @$_POST['nosurat'] : "";
		$vendor = (integer) (isset($_POST['vendor']) ? @$_POST['vendor'] : @$_GET['vendor']);
		$result=$this->m_t_negosiasi->get_nosurat_byvendor($vendor,$nosurat);
		echo $result;
	}
	
	function negodet_byfilter(){
		$branch=@$_POST["branch_id"];
		$branch=is_numeric($branch)?$branch:0;
		$project=@$_POST["project_id"];
		$project=is_numeric($project)?$project:0;
		$job=@$_POST["job_id"];
		$job=is_numeric($job)?$job:0;
	
		$result=$this->m_t_negosiasi->negodet_byfilter($branch, $project, $job);
		echo $result;
	}
	
	function badet_atkompdet_list(){
		$t_komp_id=@$_POST["t_komp_id"];
		$t_komp_id=is_numeric($t_komp_id)?$t_komp_id:0;
	
		$result=$this->m_t_negosiasi->badet_atkompdet_list($t_komp_id);
		echo $result;
	}
	
	function badet_list(){
		$t_nego_id=@$_POST["t_nego_id"];
		$t_nego_id=is_numeric($t_nego_id)?$t_nego_id:0;
		$t_komp_id=@$_POST["t_komp_id"];
		$t_komp_id=is_numeric($t_komp_id)?$t_komp_id:0;
		
		$result=$this->m_t_negosiasi->badet_list($t_nego_id, $t_komp_id);
		echo $result;
	}	
	
	function ba_list(){
		$t_nego_id=@$_POST["t_nego_id"];
		$t_nego_id=is_numeric($t_nego_id)?$t_nego_id:0;
		$t_komp_id=@$_POST["t_komp_id"];
		$t_komp_id=is_numeric($t_komp_id)?$t_komp_id:0;
		
		$result=$this->m_t_negosiasi->ba_list($t_nego_id, $t_komp_id);
		echo $result;
	}
	
	function spk_list(){
		$t_nego_id=@$_POST["t_nego_id"];
		$t_nego_id=is_numeric($t_nego_id)?$t_nego_id:0;
		$t_komp_id=@$_POST["t_komp_id"];
		$t_komp_id=is_numeric($t_komp_id)?$t_komp_id:0;
		
		$result=$this->m_t_negosiasi->spk_list($t_nego_id, $t_komp_id);
		echo $result;
	}
	
	function ba_cu(){
		$t_nego_id=@$_POST["t_nego_id"];
		$t_nego_id=is_numeric($t_nego_id)?$t_nego_id:0;
		$t_komp_id=@$_POST["t_komp_id"];
		$t_komp_id=is_numeric($t_komp_id)?$t_komp_id:0;
		$ba_date=trim(@$_POST["ba_date"]);
		$ba_date=date('Y-m-d H:i:s', strtotime($ba_date));
		$ba_vendor1=trim(@$_POST["ba_vendor1"]);
		$ba_vendor2=trim(@$_POST["ba_vendor2"]);
		$ba_vendor3=trim(@$_POST["ba_vendor3"]);
		$ba_pp1=trim(@$_POST["ba_pp1"]);
		$ba_pp2=trim(@$_POST["ba_pp2"]);
		
		//data detail
		$array_t_kompdet_id=@$_POST["t_kompdet_id"];
		$array_t_kompdet_id=json_decode(stripslashes($array_t_kompdet_id));
		$array_t_badet_vol=@$_POST["badet_vol"];
		$array_t_badet_vol=json_decode(stripslashes($array_t_badet_vol));
		$array_badet_unit=@$_POST["badet_unit"];
		$array_badet_unit=json_decode(stripslashes($array_badet_unit));
		
		$result=$this->m_t_negosiasi->ba_cu($t_nego_id, $t_komp_id, $ba_date, $ba_vendor1, $ba_vendor2, $ba_vendor3, $ba_pp1, $ba_pp2, 
				$array_t_kompdet_id, $array_t_badet_vol, $array_badet_unit);
		echo $result;
	}
	
	function spk_cu(){
		$t_nego_id=@$_POST["t_nego_id"];
		$t_nego_id=is_numeric($t_nego_id)?$t_nego_id:0;
		$spk_no=@$_POST["spk_no"];
		$spk_no = htmlentities($spk_no , ENT_QUOTES);
		$spek_field=@$_POST["spek_field"];
		$spek_field = htmlentities($spek_field , ENT_QUOTES);
		$t_komp_id=@$_POST["t_komp_id"];
		$t_komp_id=is_numeric($t_komp_id)?$t_komp_id:0;
		$spk_date=trim(@$_POST["spk_date"]);
		$spk_date=date('Y-m-d H:i:s', strtotime($spk_date));
		
		//data detail
		$array_t_kompdet_id=@$_POST["t_kompdet_id"];
		$array_t_kompdet_id=json_decode(stripslashes($array_t_kompdet_id));
		
		$array_t_spkdet_id=@$_POST["spkdet_id"];
		$array_t_spkdet_id=json_decode(stripslashes($array_t_spkdet_id));
		
		$array_spkdet_spec=@$_POST["spek_grid"];
		$array_spkdet_spec=json_decode(stripslashes($array_spkdet_spec));
		
		/* create cetak */
		
		$jenis = trim(@$_POST['jenis']);
		$jenis = htmlentities($jenis,ENT_QUOTES);
		$spek_field = trim(@$_POST['spek_field']);
		$spek_field = htmlentities($spek_field,ENT_QUOTES);
		$t_komp_id = trim(@$_POST['t_komp_id']);
		$t_komp_id = htmlentities($t_komp_id,ENT_QUOTES);
		$spk_no = trim(@$_POST['spk_no']);
		$spk_no = htmlentities($spk_no,ENT_QUOTES);
		$spk_date = trim(@$_POST['spk_date']);
		$spk_date = htmlentities($spk_date,ENT_QUOTES);
		$waktu_no = trim(@$_POST['waktu_no']);
		$waktu_no = htmlentities($waktu_no,ENT_QUOTES);
		$bayar = trim(@$_POST['bayar']);
		$bayar = htmlentities($bayar,ENT_QUOTES);
				
		$spek_grid = json_decode(stripslashes(@$_POST['spek_grid']));
		$jobdet_grid = json_decode(stripslashes(@$_POST['jobdet_grid']));

		if ($jenis == 'Umum'){
			$job_spek = $spek_field;
		}else{
			$job_spek = array();
			$i = 0;
			foreach($spek_grid  as $spek){
				$job_spek[$jobdet_grid[$i]] = $spek;
				$i++;
			}
		}
		
		$data_submit = array(
			't_komp_id' => $t_komp_id
		);
		$jenisdoc  = $this->input->post('jenisdoc');
		$jenisdoc = str_replace('<b>', '', $jenisdoc);
		$jenisdoc = str_replace(' Cetak ', '', $jenisdoc);
		$jenisdoc = str_replace('</b>', '', $jenisdoc);
		$data = $this->m_t_negosiasi->dataspk($data_submit);
		$jenis = $jenis;
		$spek = $job_spek;
		$data_table['spek'] = $spek ;
		$data_table['jenis'] = $jenis ;
		$data_table['data_table'] = $this->m_t_negosiasi->dataspkdetail($data_submit);
		$data_detail = $this->load->view('main/p_tabledetail_'.$jenisdoc,$data_table,true);
		
		$total = 0;
		foreach($data_table['data_table'] as $tb){
			$total = $total + ($tb->kompdet_price * $tb->kompdet_vol) ;
			$ppn = $total * ( 10 / 100);
			$total = $total + $ppn;
		}
		$data_find = array(
			'[#payment_name]',
			'[#spk_date]',
			'[#spk_dateend]',
			'[#spk_no]',
			'[#spk_day]',
			'[#branch_name]',
			'[#project_name]',
			'[#vendor_name]',
			'[#vendor_address]',
			'[#vendor_telp]',
			'[#vendor_fax]',
			'[#vendor_dir]',
			'[#vendor_dirpos]',
			'[#job_name]',
			'[#project_pm]',
			'[#procm_nama]',
			'[#procm_jabatan]',
			'[#kdvo_nama]',
			'[#kdvo_jabatan]',
			'[#tabel_detail]',
			'src="'
		);
		$data_replace = array(
			$bayar,
			$this->m_public_function->indonesiaDate($spk_date),
			$this->m_public_function->indonesiaDate(date('Y-m-d',strtotime($spk_date."+".$waktu_no." day"))),
			$spk_no,
			$waktu_no,
			$data->branch_name,
			$data->project_name,
			$data->vendor_name,
			$data->vendor_address,
			$data->vendor_phone,
			$data->vendor_fax,
			$data->vendor_dir,
			$data->vendor_dirpos,
			$data->job_name,
			$data->pm,
			$data->proc_name,
			$data->proc_pos,
			$data->kdvo_name,
			$data->kdvo_pos,
			$data_detail,
			'src="'.base_url()
		);
		$html = $this->m_public_function->get_kontrakcontent($jenisdoc,'Konten',$total);
		$html .= $this->m_public_function->get_kontrakcontent($jenisdoc,'Footer',$total);
		
		$html = str_replace($data_find, $data_replace, $html);
		
		 $result=$this->m_t_negosiasi->spk_cu($t_nego_id, $t_komp_id, $spk_no,$spk_date,
				$array_t_kompdet_id, $array_spkdet_spec,$spek_field,$array_t_spkdet_id,$html);
		echo $result;
	}
	
	function t_negosiasi_delete_temp(){
		$secure = @$_POST['secure'];
		$secure = htmlentities($secure);
		if ($secure){
			echo $this->m_t_negosiasi->t_negosiasi_delete_temp();
		}else{
			echo 0;
		}
	}
	
	function print_pdf_negosiasi(){
		$negosiasi_id = trim(@$_POST['negosiasi_id']);
		$data = array();
		$data['data_nego']=$this->m_t_negosiasi->get_single_negodata($negosiasi_id);
		$data['data_negodet']=$this->m_t_negosiasi->get_negodet_databynegoid($negosiasi_id);
		$data['data_negomenang']=$this->m_t_negosiasi->get_negomenang_databynegoid($negosiasi_id);
		$data['data_ambang']=$this->m_public_function->get_setupAmbang();
		$data['kdvo']=$this->m_public_function->get_param('KDVO');
		$data['procm']=$this->m_public_function->get_param('PROCM');
		$data['type']="pdf";
		$html = $this->load->view('main/p_t_negosiasi', $data, true);
		// pdf_create($html, 'seleksi', FALSE);
		file_create('print/seleksi.doc',$html);
	}
	
	function getSpkCetak(){
		$spk_id = $this->input->post('spk_id');
		echo $this->m_t_negosiasi->getSpkCetak($spk_id);
	}
	
	function print_pdf_baspk(){
/*		$this->m_public_function->clear_cache();
		$jenis = trim(@$_POST['jenis']);
		$jenis = htmlentities($jenis,ENT_QUOTES);
		$spek_field = trim(@$_POST['spek_field']);
		$spek_field = htmlentities($spek_field,ENT_QUOTES);
		$t_komp_id = trim(@$_POST['t_komp_id']);
		$t_komp_id = htmlentities($t_komp_id,ENT_QUOTES);
		$spk_no = trim(@$_POST['spk_no']);
		$spk_no = htmlentities($spk_no,ENT_QUOTES);
		$spk_date = trim(@$_POST['spk_date']);
		$spk_date = htmlentities($spk_date,ENT_QUOTES);
	//	$waktu_co = trim(@$_POST['waktu_co']);
	//	$waktu_co = htmlentities($waktu_co,ENT_QUOTES);
		$waktu_no = trim(@$_POST['waktu_no']);
		$waktu_no = htmlentities($waktu_no,ENT_QUOTES);
		$bayar = trim(@$_POST['bayar']);
		$bayar = htmlentities($bayar,ENT_QUOTES);
		
		
		$spek_grid = json_decode(stripslashes(@$_POST['spek_grid']));
		$jobdet_grid = json_decode(stripslashes(@$_POST['jobdet_grid']));

		if ($jenis == 'Umum'){
			$job_spek = $spek_field;
		}else{
			$job_spek = array();
			$i = 0;
			foreach($spek_grid  as $spek){
				$job_spek[$jobdet_grid[$i]] = $spek;
				$i++;
			}
		}
		$data_submit = array(
			't_komp_id' => $t_komp_id
		);
		
		$data = $this->m_t_negosiasi->dataspk($data_submit);
		$jenis = $jenis;
		$spek = $job_spek;
		$data_table = $this->m_t_negosiasi->dataspkdetail($data_submit);
		
		$data_detail = "<table class='gridtable' width=100%><tr>
			<th>6. No.</th>
			<th>7. Uraian Pekerjaan</th>
			<th>8. Volume</th>
			<th>9. Sat.</th>
			<th>10. Spesifikasi.</th>
			<th>11. Harga Satuan.</th>
			<th>12. Jumlah.</th>
		</tr>";
		echo count($data_table);

			$i = 0;
			$a = 0;
			
			$order = "center>".$i;
			$total = 0;
			$row = count($data_table);
			$j = 1;
			foreach($data_table as $tb){
				if ($tb->depth == 0){
					$i ++;
					$a = 0;
					$order = "center>".$i;
				}else{
					if ($a == 0 ){
						$c = 'a';
					}else{
						$c++;
					}
					$a++;
					$order = "right>".$c;
				}
				
				$data_detail .= "
				<tr valign=top>
				<td align=".$order."</td>
				<td>".$tb->jobdet_name."</td>
				<td align=right>".number_format($tb->kompdet_vol,0,',','.')."</td>
				<td >".$tb->unit_name."</td>
				";
				if (($jenis == 'Umum')){
					if ($j == 1){
						$data_detail .= "<td rowspan=".$row." >".$spek."</td>";
						$j++;
					}
				}else{
					$data_detail .= "<td >".$spek[$tb->kompdet_id]."</td>";
				} 
				$data_detail .= "
				<td align=right>".number_format($tb->kompdet_price,2,',','.')."</td>
				<td align=right>".number_format($tb->kompdet_price * $tb->kompdet_vol,2,',','.')."</td></tr>";
				$total = $total + ($tb->kompdet_price * $tb->kompdet_vol) ;
			} 
			
 		$data_detail .="
				<tr>
			<td colspan=6>Sub total<br></td>
			<td align=right>";  
				$data_detail .= number_format($total,2,',','.');
				$ppn = $total * ( 10 / 100);
		$data_detail .= "</td>
		</tr>
		<tr>
			<td colspan=6>PPN 10%</td>
			<td align=right>";
			$data_detail .= number_format($ppn,2,',','.'); 
				$total = $total + $ppn;
		$data_detail .= "</td>
		</tr>
		<tr>
			<td colspan=6>Total NK<br>Pembulatan</td>
			<td align=right>";
			$data_detail .=  number_format($total,2,',','.'); 	
		$data_detail .= "<br><b>"; 
			$data_detail .=  number_format(round($total,-3),2,',','.'); 
				$data_detail .= "</b></td>
		</tr>
		<tr>
			<td colspan=7>Terbilang : ";
			$data_detail .=  ucfirst( $this->m_public_function->terbilang(round($total,-3))); 	
		
		$data_detail .= " rupiah<br>
			(Termasuk PPN % & PPh)<br>
			<b>Sifat kontrak LUMP SUM FIXED PRICE berdasarkan gambar yang diterima</b></td>
		</tr>
	</table>
		";  

		$data_find = array(
			'[#payment_name]',
			'[#spk_date]',
			'[#spk_dateend]',
			'[#spk_no]',
			'[#spk_day]',
			'[#branch_name]',
			'[#project_name]',
			'[#vendor_name]',
			'[#vendor_address]',
			'[#vendor_telp]',
			'[#vendor_fax]',
			'[#vendor_dir]',
			'[#vendor_dirpos]',
			'[#job_name]',
			'[#project_pm]',
			'[#procm_nama]',
			'[#procm_jabatan]',
			'[#kdvo_name]',
			'[#kdvo_pos]',
			'[#tabel_detail]'
		);
		$data_replace = array(
			$bayar,
			$this->m_public_function->indonesiaDate($spk_date),
			$this->m_public_function->indonesiaDate(date('Y-m-d',strtotime($spk_date."+".$waktu_no." day"))),
			$spk_no,
			$waktu_no,
			$data->branch_name,
			$data->project_name,
			$data->vendor_name,
			$data->vendor_address,
			$data->vendor_phone,
			$data->vendor_fax,
			$data->vendor_dir,
			$data->vendor_dirpos,
			$data->job_name,
			$data->pm,
			$data->proc_name,
			$data->proc_pos,
			$data->kdvo_name,
			$data->kdvo_pos,
			$data_detail
		);
		$html = $this->m_public_function->get_kontrakcontent('SPK','Konten',100000);
		$html .= $this->m_public_function->get_kontrakcontent('SPK','Footer',100000);
		
		$html = str_replace($data_find, $data_replace, $html);
		$datahtml['html'] = $html;
		
	// echo $html;
		$html = $this->load->view('main/p_headerhtml', $datahtml, true);
		$this->m_t_negosiasi->spkUpdatePrint($spk_id,$html); */
		// $file = fopen('asdsad.html','w+');
		// fwrite($file,$html);
		$spk_id = $this->input->post('spk_id');
		$data['html'] = $this->m_t_negosiasi->getSpkCetak($spk_id);
		$html = $this->load->view('main/p_headerhtml',$data,true);
		// pdf_create($html, 'cetak_spk', FALSE);
		file_create('print/cetak.doc',$html);
		echo 1;
	}
	
	function spkSaveCetak(){
		$spk_id = $this->input->post('spk_id');
		$spk_cetak = $this->input->post('spk_cetak');
		$this->m_t_negosiasi->spkUpdatePrint($spk_id,$spk_cetak);
		echo 1;
	}
	//set index
	function index(){
		$this->load->view('main/v_t_negosiasi');
	}

	//event handler action
	function get_action(){
		$task = $_POST['task'];
		switch($task){
			case "LIST":
				$this->t_negosiasi_list();
				break;
			case "UPDATE":
				$this->t_negosiasi_update();
				break;
			case "CREATE":
				$this->t_negosiasi_create();
				break;
			case "DELETE":
				$this->t_negosiasi_delete();
				break;
			case "SEARCH":
				$this->t_negosiasi_search();
				break;
			case "PRINT":
				$this->t_negosiasi_print();
				break;
			case "EXCEL":
				$this->t_negosiasi_export_excel();
				break;
			default:
				echo "{failure:true}";
				break;
		}
	}
	
	//function fot list record
	function t_negosiasi_list(){
		
		$query = isset($_POST['query']) ? @$_POST['query'] : "";
		$start = (integer) (isset($_POST['start']) ? @$_POST['start'] : @$_GET['start']);
		$end = (integer) (isset($_POST['limit']) ? @$_POST['limit'] : @$_GET['limit']);
		$result=$this->m_t_negosiasi->t_negosiasi_list($query,$start,$end);
		echo $result;
	}
	
	//function for create new record
	function t_negosiasi_create(){
		//POST varible here
		//auto increment, don't accept anything from form values
		$branch=@$_POST["branch_id"];
		$branch=is_numeric($branch)?$branch:0;
		$project=trim(@$_POST["project_id"]);
		$project=is_numeric($project)?$project:0;
		$job=trim(@$_POST["job_id"]);
		$job=is_numeric($job)?$job:0;
		$nego_date=@$_POST["nego_date"];
		$nego_date=date('Y-m-d H:i:s', strtotime($nego_date));
		$nego_harga=trim(@$_POST["nego_harga"]);
		$nego_harga=is_numeric($nego_harga)?$nego_harga:0;
		$nego_waktu=trim(@$_POST["nego_waktu"]);
		$nego_waktu=is_numeric($nego_waktu)?$nego_waktu:0;
		$nego_waktu_satuan=trim(@$_POST["nego_waktu_satuan"]);
		$nego_bayar=trim(@$_POST["nego_bayar"]);
		
		$nego_no = $this->m_t_negosiasi->get_negono(date('Y'));
		//data detail
		$array_t_komp_id=@$_POST["t_komp_id"];
		$array_t_komp_id=json_decode(stripslashes($array_t_komp_id));
		$array_negodet_harga=@$_POST["negodet_harga"];
		$array_negodet_harga=json_decode(stripslashes($array_negodet_harga));
		$array_negodet_keahlian=@$_POST["negodet_keahlian"];
		$array_negodet_keahlian=json_decode(stripslashes($array_negodet_keahlian));
		$array_negodet_metode=@$_POST["negodet_metode"];
		$array_negodet_metode=json_decode(stripslashes($array_negodet_metode));
		$array_negodet_peralatan=@$_POST["negodet_peralatan"];
		$array_negodet_peralatan=json_decode(stripslashes($array_negodet_peralatan));
		$array_negodet_k3l=@$_POST["negodet_k3l"];
		$array_negodet_k3l=json_decode(stripslashes($array_negodet_k3l));
		$array_negodet_waktu=@$_POST["negodet_waktu"];
		$array_negodet_waktu=json_decode(stripslashes($array_negodet_waktu));
		$array_negodet_bayar=@$_POST["negodet_bayar"];
		$array_negodet_bayar=json_decode(stripslashes($array_negodet_bayar));
		$array_negodet_lulus=@$_POST["negodet_lulus"];
		$array_negodet_lulus=json_decode(stripslashes($array_negodet_lulus));
		$array_negodet_menang=@$_POST["negodet_menang"];
		$array_negodet_menang=json_decode(stripslashes($array_negodet_menang));
		$array_negodet_kp=@$_POST["negodet_kp"];
		$array_negodet_kp=json_decode(stripslashes($array_negodet_kp));
		
		$result=$this->m_t_negosiasi->t_negosiasi_create($branch, $project, $job, $nego_date, $nego_harga, $nego_waktu, $nego_waktu_satuan, $nego_bayar,$nego_no, 
				$array_t_komp_id, $array_negodet_harga, $array_negodet_keahlian, $array_negodet_metode, $array_negodet_peralatan, $array_negodet_k3l, 
				$array_negodet_waktu, $array_negodet_bayar, $array_negodet_lulus, $array_negodet_menang,$array_negodet_kp);
		echo $result;
	}
	
	
	//function for update record
	function t_negosiasi_update(){
		//POST variable here
		$nego_id=@$_POST["nego_id"];
		$nego_id=is_numeric($nego_id)?$nego_id:0;
		$branch=@$_POST["branch_id"];
		$branch=is_numeric($branch)?$branch:0;
		$project=trim(@$_POST["project_id"]);
		$project=is_numeric($project)?$project:0;
		$job=trim(@$_POST["job_id"]);
		$job=is_numeric($job)?$job:0;
		$nego_date=@$_POST["nego_date"];
		$nego_date=date('Y-m-d H:i:s', strtotime($nego_date));
		$nego_harga=trim(@$_POST["nego_harga"]);
		$nego_harga=is_numeric($nego_harga)?$nego_harga:0;
		$nego_waktu=trim(@$_POST["nego_waktu"]);
		$nego_waktu=is_numeric($nego_waktu)?$nego_waktu:0;
		$nego_waktu_satuan=trim(@$_POST["nego_waktu_satuan"]);
		$nego_bayar=trim(@$_POST["nego_bayar"]);
		//data detail
		$array_negodet_id=@$_POST["negodet_id"];
		$array_negodet_id=json_decode(stripslashes($array_negodet_id));
		$array_t_komp_id=@$_POST["t_komp_id"];
		$array_t_komp_id=json_decode(stripslashes($array_t_komp_id));
		$array_negodet_harga=@$_POST["negodet_harga"];
		$array_negodet_harga=json_decode(stripslashes($array_negodet_harga));
		$array_negodet_keahlian=@$_POST["negodet_keahlian"];
		$array_negodet_keahlian=json_decode(stripslashes($array_negodet_keahlian));
		$array_negodet_metode=@$_POST["negodet_metode"];
		$array_negodet_metode=json_decode(stripslashes($array_negodet_metode));
		$array_negodet_peralatan=@$_POST["negodet_peralatan"];
		$array_negodet_peralatan=json_decode(stripslashes($array_negodet_peralatan));
		$array_negodet_k3l=@$_POST["negodet_k3l"];
		$array_negodet_k3l=json_decode(stripslashes($array_negodet_k3l));
		$array_negodet_waktu=@$_POST["negodet_waktu"];
		$array_negodet_waktu=json_decode(stripslashes($array_negodet_waktu));
		$array_negodet_bayar=@$_POST["negodet_bayar"];
		$array_negodet_bayar=json_decode(stripslashes($array_negodet_bayar));
		$array_negodet_lulus=@$_POST["negodet_lulus"];
		$array_negodet_lulus=json_decode(stripslashes($array_negodet_lulus));
		$array_negodet_menang=@$_POST["negodet_menang"];
		$array_negodet_menang=json_decode(stripslashes($array_negodet_menang));
		$array_negodet_kp=@$_POST["negodet_kp"];
		$array_negodet_kp=json_decode(stripslashes($array_negodet_kp));
		
		$result = $this->m_t_negosiasi->t_negosiasi_update($nego_id, $branch, $project, $job, $nego_date, $nego_harga, $nego_waktu, $nego_waktu_satuan, $nego_bayar, 
				$array_negodet_id, $array_t_komp_id, $array_negodet_harga, $array_negodet_keahlian, $array_negodet_metode, $array_negodet_peralatan, $array_negodet_k3l, 
				$array_negodet_waktu, $array_negodet_bayar, $array_negodet_lulus, $array_negodet_menang,$array_negodet_kp);
		echo $result;
	}
	
	//function for delete selected record
	function t_negosiasi_delete(){
		$ids = @$_POST['ids']; // Get our array back and translate it :
		$pkid = json_decode(stripslashes($ids));
		$result=$this->m_t_negosiasi->t_negosiasi_delete($pkid);
		echo $result;
	}

	//function for advanced search
	function t_negosiasi_search(){
		//POST varibale here
		$negosiasi_id=@$_POST["negosiasi_id"];
		$negosiasi_id=is_numeric($negosiasi_id)?$negosiasi_id:0;
		$negosiasi_flag=trim(@$_POST["negosiasi_flag"]);
		$negosiasi_flag=htmlentities($negosiasi_flag,ENT_QUOTES);
		$job=trim(@$_POST["job"]);
		$job=htmlentities($job,ENT_QUOTES);
		$project=trim(@$_POST["project"]);
		$project=htmlentities($project,ENT_QUOTES);
		$negosiasi_name=trim(@$_POST["negosiasi_name"]);
		$negosiasi_name=htmlentities($negosiasi_name,ENT_QUOTES);
		$negosiasi_shortname=trim(@$_POST["negosiasi_shortname"]);
		$negosiasi_shortname=htmlentities($negosiasi_shortname,ENT_QUOTES);
		$negosiasi_pm=trim(@$_POST["negosiasi_pm"]);
		$negosiasi_pm=htmlentities($negosiasi_pm,ENT_QUOTES);
		$negosiasi_semcm=trim(@$_POST["negosiasi_semcm"]);
		$negosiasi_semcm=htmlentities($negosiasi_semcm,ENT_QUOTES);
		$negosiasi_value=trim(@$_POST["negosiasi_value"]);
		$negosiasi_start=trim(@$_POST["negosiasi_start"]);
		$negosiasi_p1=trim(@$_POST["negosiasi_p1"]);
		$negosiasi_p2=trim(@$_POST["negosiasi_p2"]);
		$negosiasi_created_date=trim(@$_POST["negosiasi_created_date"]);
		$negosiasi_created_by=trim(@$_POST["negosiasi_created_by"]);
		$negosiasi_created_by=htmlentities($negosiasi_created_by,ENT_QUOTES);
		$negosiasi_updated_date=trim(@$_POST["negosiasi_updated_date"]);
		$negosiasi_updated_by=trim(@$_POST["negosiasi_updated_by"]);
		$negosiasi_updated_by=htmlentities($negosiasi_updated_by,ENT_QUOTES);
		$negosiasi_updated_count=@$_POST["negosiasi_updated_count"];
		$negosiasi_updated_count=is_numeric($negosiasi_updated_count)?$negosiasi_updated_count:0;
		$branch=@$_POST["branch_id"];
		$branch=is_numeric($branch)?$branch:0;
		
		$start = (integer) (isset($_POST['start']) ? $_POST['start'] : $_GET['start']);
		$end = (integer) (isset($_POST['limit']) ? $_POST['limit'] : $_GET['limit']);
		$result = $this->m_t_negosiasi->t_negosiasi_search($negosiasi_id ,$negosiasi_flag ,$job ,$project ,$negosiasi_name ,$negosiasi_shortname ,$negosiasi_pm ,$negosiasi_semcm ,$negosiasi_value ,$negosiasi_start ,$negosiasi_p1 ,$negosiasi_p2 ,$negosiasi_created_date ,$negosiasi_created_by ,$negosiasi_updated_date ,$negosiasi_updated_by ,$negosiasi_updated_count ,$branch ,$start,$end);
		echo $result;
	}


	function t_negosiasi_print(){
  		//POST varibale here
		$negosiasi_id=@$_POST["negosiasi_id"];
		$negosiasi_id=is_numeric($negosiasi_id)?$negosiasi_id:0;
		$negosiasi_flag=trim(@$_POST["negosiasi_flag"]);
		$negosiasi_flag=htmlentities($negosiasi_flag,ENT_QUOTES);
		$job=trim(@$_POST["job"]);
		$job=htmlentities($job,ENT_QUOTES);
		$project=trim(@$_POST["project"]);
		$project=htmlentities($project,ENT_QUOTES);
		$negosiasi_name=trim(@$_POST["negosiasi_name"]);
		$negosiasi_name=htmlentities($negosiasi_name,ENT_QUOTES);
		$negosiasi_shortname=trim(@$_POST["negosiasi_shortname"]);
		$negosiasi_shortname=htmlentities($negosiasi_shortname,ENT_QUOTES);
		$negosiasi_pm=trim(@$_POST["negosiasi_pm"]);
		$negosiasi_pm=htmlentities($negosiasi_pm,ENT_QUOTES);
		$negosiasi_semcm=trim(@$_POST["negosiasi_semcm"]);
		$negosiasi_semcm=htmlentities($negosiasi_semcm,ENT_QUOTES);
		$negosiasi_value=trim(@$_POST["negosiasi_value"]);
		$negosiasi_start=trim(@$_POST["negosiasi_start"]);
		$negosiasi_p1=trim(@$_POST["negosiasi_p1"]);
		$negosiasi_p2=trim(@$_POST["negosiasi_p2"]);
		$negosiasi_created_date=trim(@$_POST["negosiasi_created_date"]);
		$negosiasi_created_by=trim(@$_POST["negosiasi_created_by"]);
		$negosiasi_created_by=htmlentities($negosiasi_created_by,ENT_QUOTES);
		$negosiasi_updated_date=trim(@$_POST["negosiasi_updated_date"]);
		$negosiasi_updated_by=trim(@$_POST["negosiasi_updated_by"]);
		$negosiasi_updated_by=htmlentities($negosiasi_updated_by,ENT_QUOTES);
		$negosiasi_updated_count=@$_POST["negosiasi_updated_count"];
		$negosiasi_updated_count=is_numeric($negosiasi_updated_count)?$negosiasi_updated_count:0;
		$branch=@$_POST["branch_id"];
		$branch=is_numeric($branch)?$branch:0;
		$option=$_POST['currentlisting'];
		$filter=$_POST["query"];
		
		$data["data_print"] = $this->m_t_negosiasi->t_negosiasi_print($negosiasi_id ,$negosiasi_flag ,$job ,$project ,$negosiasi_name ,$negosiasi_shortname ,$negosiasi_pm ,$negosiasi_semcm ,$negosiasi_value ,$negosiasi_start ,$negosiasi_p1 ,$negosiasi_p2 ,$negosiasi_created_date ,$negosiasi_created_by ,$negosiasi_updated_date ,$negosiasi_updated_by ,$negosiasi_updated_count ,$branch ,$option,$filter);
		$print_view=$this->load->view("main/p_t_negosiasi.php",$data,TRUE);
		if(!file_exists("print")){
			mkdir("print");
		}
		$print_file=fopen("print/t_negosiasi_printlist.html","w+");
		fwrite($print_file, $print_view);
		echo '1';        
	}
	/* End Of Function */

	/* Function to Export Excel document */
	function t_negosiasi_export_excel(){
		//POST varibale here
		$negosiasi_id=@$_POST["negosiasi_id"];
		$negosiasi_id=is_numeric($negosiasi_id)?$negosiasi_id:0;
		$negosiasi_flag=trim(@$_POST["negosiasi_flag"]);
		$negosiasi_flag=htmlentities($negosiasi_flag,ENT_QUOTES);
		$job=trim(@$_POST["job"]);
		$job=htmlentities($job,ENT_QUOTES);
		$project=trim(@$_POST["project"]);
		$project=htmlentities($project,ENT_QUOTES);
		$negosiasi_name=trim(@$_POST["negosiasi_name"]);
		$negosiasi_name=htmlentities($negosiasi_name,ENT_QUOTES);
		$negosiasi_shortname=trim(@$_POST["negosiasi_shortname"]);
		$negosiasi_shortname=htmlentities($negosiasi_shortname,ENT_QUOTES);
		$negosiasi_pm=trim(@$_POST["negosiasi_pm"]);
		$negosiasi_pm=htmlentities($negosiasi_pm,ENT_QUOTES);
		$negosiasi_semcm=trim(@$_POST["negosiasi_semcm"]);
		$negosiasi_semcm=htmlentities($negosiasi_semcm,ENT_QUOTES);
		$negosiasi_value=trim(@$_POST["negosiasi_value"]);
		$negosiasi_start=trim(@$_POST["negosiasi_start"]);
		$negosiasi_p1=trim(@$_POST["negosiasi_p1"]);
		$negosiasi_p2=trim(@$_POST["negosiasi_p2"]);
		$negosiasi_created_date=trim(@$_POST["negosiasi_created_date"]);
		$negosiasi_created_by=trim(@$_POST["negosiasi_created_by"]);
		$negosiasi_created_by=htmlentities($negosiasi_created_by,ENT_QUOTES);
		$negosiasi_updated_date=trim(@$_POST["negosiasi_updated_date"]);
		$negosiasi_updated_by=trim(@$_POST["negosiasi_updated_by"]);
		$negosiasi_updated_by=htmlentities($negosiasi_updated_by,ENT_QUOTES);
		$negosiasi_updated_count=@$_POST["negosiasi_updated_count"];
		$negosiasi_updated_count=is_numeric($negosiasi_updated_count)?$negosiasi_updated_count:0;
		$branch=@$_POST["branch_id"];
		$branch=is_numeric($branch)?$branch:0;
		$option=$_POST['currentlisting'];
		$filter=$_POST["query"];
		$data["type"]="excel";
		$data["data_print"] = $this->m_t_negosiasi->t_negosiasi_print($negosiasi_id ,$negosiasi_flag ,$job ,$project ,$negosiasi_name ,$negosiasi_shortname ,$negosiasi_pm ,$negosiasi_semcm ,$negosiasi_value ,$negosiasi_start ,$negosiasi_p1 ,$negosiasi_p2 ,$negosiasi_created_date ,$negosiasi_created_by ,$negosiasi_updated_date ,$negosiasi_updated_by ,$negosiasi_updated_count ,$branch ,$option,$filter);
		$print_view=$this->load->view("main/p_t_negosiasi.php",$data,TRUE);
		if(!file_exists("print")){
			mkdir("print");
		}
		$print_file=fopen("print/t_negosiasi_printlist.xls","w+");
		fwrite($print_file, $print_view);
		echo '1';   
			
	}
	
	// Encodes a SQL array into a JSON formated string
	function JEncode($arr){
		if (version_compare(PHP_VERSION,"5.2","<"))
		{    
			require_once("./JSON.php"); //if php<5.2 need JSON class
			$json = new Services_JSON();//instantiate new json object
			$data=$json->encode($arr);  //encode the data in json format
		} else {
			$data = json_encode($arr);  //encode the data in json format
		}
		return $data;
	}
	
	// Decode a SQL array into a JSON formated string
	function JDecode($arr){
		if (version_compare(PHP_VERSION,"5.2","<"))
		{    
			require_once("./JSON.php"); //if php<5.2 need JSON class
			$json = new Services_JSON();//instantiate new json object
			$data=$json->decode($arr);  //decode the data in json format
		} else {
			$data = json_decode($arr);  //decode the data in json format
		}
		return $data;
	}
		
}
?>